<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" class="input" />
    <button class="btn">计算</button>
    <script>
      /*
        斐波那契数列：
          1 1 2 3 5 8 13 21 34 55 89
      */

      // function fibonacci(num) {
      //   return num < 3 ? 1 : fibonacci(num - 2) + fibonacci(num - 1);
      // }

      const inputEl = document.querySelector(".input");

      const calc = new Worker("./calcWorker.js", {
        type: "module",
      });

      document.querySelector(".btn").onclick = function () {
        const num = +inputEl.value;
        // const result = fibonacci(num);
        // console.log(result);
        calc.postMessage(num);

        calc.onmessage = function (e) {
          console.log("计算结果", e.data);
        };
      };
    </script>
  </body>
</html>
